package com.woniuxy.enjoylife.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniuxy.enjoylife.entity.Goods_order;
import com.woniuxy.enjoylife.entity.dto.ReturnGoodsOrderDto;
import com.woniuxy.enjoylife.entity.dto.SelectGoodsOrderDto;
import com.woniuxy.enjoylife.mapper.Goods_orderMapper;
import com.woniuxy.enjoylife.service.Goods_orderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.enjoylife.utils.PageResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author teamEnjoyLife75
 * @since 2021-01-23
 */
@Service
public class Goods_orderServiceImpl extends ServiceImpl<Goods_orderMapper, Goods_order> implements Goods_orderService {
    @Resource
    private Goods_orderMapper goodsOrderMapper;

    @Override
    public PageResult<ReturnGoodsOrderDto> selectGoodsOrderDto(SelectGoodsOrderDto dto) {
        if (null!=dto.getInformation()&&dto.getInformation().length()!=0){
            dto.setInformation("%"+dto.getInformation()+"%");
        }
        Page<Object> page = PageHelper.startPage(dto.getPage(), dto.getSize());
        List<ReturnGoodsOrderDto> returnGoodsOrderDtoList = goodsOrderMapper.selectDto(dto);

        PageResult<ReturnGoodsOrderDto> result=new PageResult<>();

        result.setData(returnGoodsOrderDtoList).setTotal(page.getTotal()).setTotalPage(page.getPageNum()).setCurrentPage(dto.getPage()).setPageSize(dto.getSize());
        return result;
    }

    @Override
    public Boolean deleteOrder(int id) {

        return goodsOrderMapper.deleteOrder(id);
    }

    @Override
    public Boolean updateOrder(Goods_order order) {
        return goodsOrderMapper.updateOrder(order);
    }

}
